﻿Imports System.Data.SqlClient

Public Class clsUBICACIONES
    Public Sub ELIMINA_UBICACION(ByVal CODIGO_PRODUCTO As String, ByVal NOMBRE_ALMACEN As String, ByVal TIPO As Integer)
        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand("ELIMINA_UBICACION", cnConn)
        Command.CommandType = CommandType.StoredProcedure

        Command.Parameters.Add(New SqlParameter("@CODIGO", SqlDbType.VarChar, 30))
        Command.Parameters("@CODIGO").Value = CODIGO_PRODUCTO
        Command.Parameters.Add(New SqlParameter("@ALMACEN", SqlDbType.VarChar, 150))
        Command.Parameters("@ALMACEN").Value = NOMBRE_ALMACEN
        Command.Parameters.Add(New SqlParameter("@TIPO", SqlDbType.Int))
        Command.Parameters("@TIPO").Value = TIPO

        Try
            cnConn.Open()
            Command.ExecuteNonQuery()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Information, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End Try


    End Sub
    Public Function VALIDA_UBICACION(ByVal CODIGO_PRODUCTO As String, ByVal NOMBRE_ALMACEN As String, ByVal TIPO As Integer) As Integer
        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand("sp_VALIDA_UBICACION", cnConn)
        Command.CommandType = CommandType.StoredProcedure

        Command.Parameters.Add(New SqlParameter("@CODIGO", SqlDbType.VarChar, 30))
        Command.Parameters("@CODIGO").Value = CODIGO_PRODUCTO
        Command.Parameters.Add(New SqlParameter("@ALMACEN", SqlDbType.VarChar, 150))
        Command.Parameters("@ALMACEN").Value = NOMBRE_ALMACEN
        Command.Parameters.Add(New SqlParameter("@TIPO", SqlDbType.Int))
        Command.Parameters("@TIPO").Value = TIPO

        Dim Lector As SqlDataReader
        Try
            cnConn.Open()
            Lector = Command.ExecuteReader

            If Lector.Read() Then
                VALIDA_UBICACION = Lector("RESULTADO")
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Information, "Aviso")
            VALIDA_UBICACION = -1
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End Try


    End Function
    Public Function INSERTA_UBICACION(ByVal CODIGO As String, ByVal NOMBRE As String, ByVal ALMACEN As String, ByVal ZONA As String, ByVal PASILLO As String, ByVal ANAQUEL As String, ByVal REPISA As String, ByVal TIPO As Integer, ByVal PROPIETARIO As String, ByVal ESTATUS As Integer, ByVal INFO_EX As String) As Integer
        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand("sp_UBICACIONES", cnConn)
        Command.CommandType = CommandType.StoredProcedure

        Command.Parameters.Add(New SqlParameter("@CODIGO", SqlDbType.VarChar, 30))
        Command.Parameters("@CODIGO").Value = CODIGO
        Command.Parameters.Add(New SqlParameter("@ALMACEN", SqlDbType.VarChar, 150))
        Command.Parameters("@ALMACEN").Value = ALMACEN
        Command.Parameters.Add(New SqlParameter("@ZONA", SqlDbType.VarChar, 100))
        Command.Parameters("@ZONA").Value = ZONA
        Command.Parameters.Add(New SqlParameter("@PASILLO", SqlDbType.VarChar, 100))
        Command.Parameters("@PASILLO").Value = PASILLO
        Command.Parameters.Add(New SqlParameter("@ANAQUEL", SqlDbType.VarChar, 100))
        Command.Parameters("@ANAQUEL").Value = ANAQUEL
        Command.Parameters.Add(New SqlParameter("@REPISA", SqlDbType.VarChar, 100))
        Command.Parameters("@REPISA").Value = REPISA
        Command.Parameters.Add(New SqlParameter("@TIPO", SqlDbType.Int))
        Command.Parameters("@TIPO").Value = TIPO
        Command.Parameters.Add(New SqlParameter("@NOM_PRO", SqlDbType.VarChar, 200))
        Command.Parameters("@NOM_PRO").Value = PROPIETARIO
        Command.Parameters.Add(New SqlParameter("@ESTATUS", SqlDbType.Int))
        Command.Parameters("@ESTATUS").Value = ESTATUS
        Command.Parameters.Add(New SqlParameter("@INFO_MAX", SqlDbType.VarChar, 2000))
        Command.Parameters("@INFO_MAX").Value = INFO_EX
        Command.Parameters.Add(New SqlParameter("@NOMBRE", SqlDbType.VarChar, 150))
        Command.Parameters("@NOMBRE").Value = NOMBRE
        Command.Parameters.Add(New SqlParameter("@NOMBRE_USUARIO", SqlDbType.VarChar, 50))
        Command.Parameters("@NOMBRE_USUARIO").Value = UsuarioActivo

        Try
            cnConn.Open()
            Dim rdBuscar As SqlDataReader = Command.ExecuteReader()
            If rdBuscar.Read() Then
                INSERTA_UBICACION = rdBuscar("RESULTADO")
            End If
        Catch ex As Exception
            INSERTA_UBICACION = -1
            MsgBox(ex.Message, MsgBoxStyle.Information, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End Try


    End Function
End Class
